/*     */ package com.chw.admin.user;
/*     */ 
/*     */ import com.chw.annotation.PermissionSecurity;
/*     */ import com.chw.common.SecureInfo;
/*     */ import com.chw.common.ServiceData;
/*     */ import com.chw.common.ServiceData.RetCode;
/*     */ import com.chw.utils.LogUtil;
/*     */ import com.github.pagehelper.PageInfo;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpSession;
/*     */ import org.jasig.cas.client.authentication.AttributePrincipal;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/sysUser"})
/*     */ public class SysUserController
/*     */ {
/*  24 */   private static LogUtil log = LogUtil.newInstance(SysUserController.class);
/*     */ 
/*     */   @Autowired
/*     */   private ISysUserService sysUserService;
/*     */ 
/*  32 */   @RequestMapping(value={"/getCurrentUser.notPermSc"}, method={org.springframework.web.bind.annotation.RequestMethod.GET}, consumes={"*/*"}, produces={"application/json"})
/*     */   @ResponseBody
/*     */   public ServiceData getCurrentUser(HttpServletRequest request) throws Exception { log.info("getCurrentUser");
/*     */ 
/*  34 */     ServiceData ret = new ServiceData();
/*  35 */     AttributePrincipal principal = (AttributePrincipal)request.getUserPrincipal();
/*  36 */     if (principal != null) {
/*  37 */       Map attributes = principal.getAttributes();
/*  38 */       attributes.put("secureToken", new SecureInfo((String)attributes.get("id")).encode());
/*  39 */       ret.setBo(attributes);
/*     */     } else {
/*  41 */       ret.setBo(request.getSession().getAttribute("account"));
/*     */     }
/*  43 */     return ret; } 
/*     */   @RequestMapping(value={"/pageSysUser"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}, consumes={"*/*"}, produces={"application/json"})
/*     */   @ResponseBody
/*     */   @PermissionSecurity(name="查询", module="用户管理", btnfunc="select_user")
/*     */   public ServiceData page(HttpServletRequest request, SysUser user, Integer currentPage, Integer pageSize) throws Exception {
/*  51 */     log.info("page");
/*     */ 
/*  53 */     ServiceData ret = new ServiceData();
/*  54 */     PageInfo users = this.sysUserService.page(user, currentPage.intValue(), pageSize.intValue());
/*  55 */     ret.setCode(request, ServiceData.RetCode.Success);
/*  56 */     ret.setBo(users);
/*  57 */     return ret;
/*     */   }
/*  65 */   @RequestMapping(value={"/save"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}, consumes={"*/*"}, produces={"application/json"})
/*     */   @ResponseBody
/*     */   @PermissionSecurity(name="新增", module="用户管理", btnfunc="add_user")
/*     */   public ServiceData save(HttpServletRequest request, SysUser user) throws Exception { ServiceData ret = new ServiceData();
/*  66 */     this.sysUserService.saveOrUpdate(user);
/*  67 */     ret.setCode(request, ServiceData.RetCode.Success);
/*  68 */     return ret; } 
/*     */   @RequestMapping(value={"/update"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}, consumes={"*/*"}, produces={"application/json"})
/*     */   @ResponseBody
/*     */   @PermissionSecurity(name="修改", module="用户管理", btnfunc="update_user")
/*     */   public ServiceData update(HttpServletRequest request, SysUser user) throws Exception {
/*  76 */     ServiceData ret = new ServiceData();
/*  77 */     this.sysUserService.saveOrUpdate(user);
/*  78 */     ret.setCode(request, ServiceData.RetCode.Success);
/*  79 */     return ret; } 
/*  86 */   @RequestMapping(value={"/get"}, method={org.springframework.web.bind.annotation.RequestMethod.GET}, consumes={"*/*"}, produces={"application/json"})
/*     */   @ResponseBody
/*     */   @PermissionSecurity(name="查询", module="用户管理", btnfunc="select_user")
/*     */   public ServiceData get(HttpServletRequest request, String id) throws Exception { log.info("get");
/*     */ 
/*  88 */     ServiceData ret = new ServiceData();
/*  89 */     SysUser user = this.sysUserService.selectById(id);
/*  90 */     ret.setBo(user);
/*  91 */     ret.setCode(request, ServiceData.RetCode.Success);
/*  92 */     return ret; } 
/*  99 */   @RequestMapping(value={"/updateStatus"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}, consumes={"*/*"}, produces={"application/json"})
/*     */   @ResponseBody
/*     */   @PermissionSecurity(name="启用禁用", module="用户管理", btnfunc="update_user_status")
/*     */   public void updateStatus(HttpServletRequest request, String id, String status) throws Exception { this.sysUserService.updateStatus(id, status); } 
/* 106 */   @RequestMapping(value={"/resetException"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}, consumes={"*/*"}, produces={"application/json"})
/*     */   @ResponseBody
/*     */   @PermissionSecurity(name="启用禁用", module="用户管理", btnfunc="update_user_status")
/*     */   public void resetException(HttpServletRequest request, String id) throws Exception { if ((id != null) && (id.length() > 0))
/* 107 */       this.sysUserService.resetException(id);  }
/*     */ 
/*     */   @RequestMapping(value={"/delete"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}, consumes={"*/*"}, produces={"application/json"})
/*     */   @ResponseBody
/*     */   @PermissionSecurity(name="删除", module="用户管理", btnfunc="delete_user")
/*     */   public void delete(HttpServletRequest request, String id) throws Exception {
/* 115 */     log.info("delete");
/* 116 */     this.sysUserService.delete(id); } 
/* 123 */   @RequestMapping(value={"/hasAccountSysUser"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}, consumes={"*/*"}, produces={"application/json"})
/*     */   @ResponseBody
/*     */   @PermissionSecurity(name="查询", module="用户管理", btnfunc="select_user")
/*     */   public ServiceData hasAccount(HttpServletRequest request, String name, String id) throws Exception { ServiceData ret = new ServiceData();
/* 124 */     boolean flag = this.sysUserService.hasAccount(name, id);
/* 125 */     ret.setBo(Boolean.valueOf(flag));
/* 126 */     ret.setCode(request, ServiceData.RetCode.Success);
/* 127 */     return ret; } 
/* 134 */   @RequestMapping(value={"/hasNameAndAccount"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}, consumes={"*/*"}, produces={"application/json"})
/*     */   @ResponseBody
/*     */   @PermissionSecurity(name="查询", module="查询用户名称是否重复", btnfunc="select_user")
/*     */   public ServiceData hasNameAndAccount(HttpServletRequest request, SysUser record) throws Exception { ServiceData ret = new ServiceData();
/* 135 */     boolean flag = this.sysUserService.hasNameAndAccount(record);
/* 136 */     ret.setBo(Boolean.valueOf(flag));
/* 137 */     ret.setCode(request, ServiceData.RetCode.Success);
/* 138 */     return ret; } 
/* 145 */   @RequestMapping(value={"/pwdOld"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}, consumes={"*/*"}, produces={"application/json"})
/*     */   @ResponseBody
/*     */   @PermissionSecurity(name="查询", module="查询输入的旧密码是否正确", btnfunc="select_user")
/*     */   public ServiceData pwdOld(HttpServletRequest request, String pwdOld, String id) throws Exception { ServiceData ret = new ServiceData();
/* 146 */     boolean flag = this.sysUserService.pwdOld(pwdOld, id);
/* 147 */     ret.setBo(Boolean.valueOf(flag));
/* 148 */     ret.setCode(request, ServiceData.RetCode.Success);
/* 149 */     return ret; } 
/*     */   @RequestMapping(value={"/getUserType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}, consumes={"*/*"}, produces={"application/json"})
/*     */   @ResponseBody
/*     */   @PermissionSecurity(name="判断当前用户", module="判断当前用户类型", btnfunc="add_user")
/*     */   public ServiceData getUserType(HttpServletRequest request) throws Exception {
/* 157 */     ServiceData ret = new ServiceData();
/* 158 */     boolean isRole = this.sysUserService.isRole();
/* 159 */     ret.setCode(request, ServiceData.RetCode.Success);
/* 160 */     ret.setBo(Boolean.valueOf(isRole));
/* 161 */     return ret;
/*     */   }
/*     */ }
